# -- coding:UTF-8 --

import os
import sys
import time
import imghdr

# 项目地址
Path_Project = sys.path[0]


def printNow(str):
    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + " " + str)
    sys.stdout.flush()

def checkImg(filePath):
    (file, ext) = os.path.splitext(filePath)
    tt = imghdr.what(filePath)
    if (tt == "png") and (ext != ".png"):
        print("error:", filePath, ext, tt)
    if (tt == "jpeg") and (not ((ext == ".jpg") or (ext == ".jpeg"))):
        print("error:", filePath, ext, tt)


def findPng(folderPath, extend_name):
    for item in os.listdir(folderPath):
        if os.path.isdir(os.path.join(folderPath, item)):
            subFolderPath = os.path.join(folderPath, item)
            findPng(subFolderPath, extend_name)
        else:
            filePath = os.path.join(folderPath, item)
            if (os.path.isfile(filePath)):
                if item.split('.')[-1] in extend_name:
                    checkImg(filePath)


# ---------------------------------main----------------------------#
findPng(Path_Project + "\\assets", ["png", "jpg", "jpeg"])

printNow("done...\n")
os.system('pause')
